<template>
  <svg :viewBox="svg.viewBox" :class="['icon', { fillScreen: fillScreen }]" :style="{ fontSize: size }" @click="$emit('click')">
    <use :xlink:href="svg.url" />
  </svg>
</template>

<script>
export default {
  name: "SvgIcon",
  props: {
    name: {
      require: true,
      type: String
    },
    size: {
      default: 24,
      type: Number
    },
    fillScreen: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
    }
  },
  computed: {
    svg(){
      const { url, viewBox } = require(`../assets/icons/${this.name}.svg`).default
      return { url, viewBox }
    }
  },
  created() {
    // const svg = require(`../assets/icons/${this.name}.svg`).default
    // this.link = svg.url
    // this.viewBox = svg.viewBox
  }
}
</script>

<style lang="less" scoped>
  .icon {
    width: 1em;
    height: 1em;
    fill: currentColor;
    vertical-align: middle;
    cursor: pointer;
    &.fillScreen {
      width: 100%;
      height: 100vh;
    }
  }
</style>